﻿Imports System.Data.OleDb

Public Class NewTemplate

    Dim insertedLayers As Integer = 1
    Dim Tid As Integer = 0
    Dim innerLayer As String = "overflow-y: auto; overflow-x: hidden;	word-wrap: break-word ; z-index: 1"



    Private Sub TemplateBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.TemplateBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DigitalDocumentDataSet)

    End Sub

    Private Sub NewTemplate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DigitalDocumentDataSet.Layer' table. You can move, or remove it, as needed.
        Me.LayerTableAdapter.Fill(Me.DigitalDocumentDataSet.Layer)
        'TODO: This line of code loads data into the 'DigitalDocumentDataSet.Template' table. You can move, or remove it, as needed.
        Me.TemplateTableAdapter.Fill(Me.DigitalDocumentDataSet.Template)
        LayerMake.Visible = False
        ExistsTemplate.Enabled = False
        Panel1.Visible = False

    End Sub


    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MsgBox("Fill the field")
        Else



            Me.TemplateTableAdapter.Insert(Me.TextBox1.Text, Me.TextBox2.Text)

            Me.TemplateTableAdapter.Fill(Me.DigitalDocumentDataSet.Template)
            numlayer.Text = TextBox2.Text + " Layers"
            LayerMake.Visible = True
            TextBox1.Enabled = False
            'MsgBox("completed")
            Dim strSQL As String = "SELECT Max(Tid) as cc FROM Template"
            Try
                Using cnn As New OleDbConnection(My.Settings.DigitalDocumentConnectionString)
                    Using cmd As New OleDbCommand(strSQL, cnn)
                        cnn.Open()

                        Using dr As OleDbDataReader = cmd.ExecuteReader()
                            ' Loop through all the rows, retrieving the 
                            ' columns you need. Also look into the GetString
                            ' method (and other Get... methods) for a faster 
                            ' way to retrieve individual columns.

                            While dr.Read

                                Tid = dr("cc")
                            End While
                            cnn.Close()

                        End Using
                    End Using
                End Using

            Catch ex As Exception
                MessageBox.Show(ex.Message)

            End Try


            Me.Size = New System.Drawing.Size(342, 302)
            Panel1.Visible = True
        End If
    End Sub

    Private Sub PossitionXLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'add
        Dim flag As Boolean = True
        Dim problem As String = ""
        Dim counter As Integer = 0
        Dim posx As String = TextBox3.Text + "%"
        Dim posy As String = TextBox4.Text + "%"
        Dim dimex As String = TextBox5.Text + "%"
        Dim dimey As String = TextBox6.Text + "%"

        If posx = "" Then
            problem += "Position X ,"
            flag = False
            counter = counter + 1
        End If

        If posy = "" Then
            counter = counter + 1
            problem += "Position Y ,"
            flag = False
        End If

        If dimex = "" Then
            counter = counter + 1
            problem += "Dissmention X ,"
            flag = False
        End If

        If dimey = "" Then
            counter = counter + 1
            problem += "Dissmention X ,"
            flag = False
        End If
        If problem.Length > 3 Then
            problem = problem.Substring(0, problem.Length - 1)
        End If


        If counter > 1 Then
            problem += " are Empty"
        Else
            problem += " is Empty"
        End If



        If flag Then
            If insertedLayers = 1 Then
                Me.LayerTableAdapter.Insert(Tid, posx, posy, dimex, dimey, "relative", innerLayer, insertedLayers)
            Else
                Me.LayerTableAdapter.Insert(Tid, posx, posy, dimex, dimey, "absolute", innerLayer, insertedLayers)
            End If
            LayerMake.Items.Add("Layer " + insertedLayers.ToString + " complete")

            insertedLayers = insertedLayers + 1
            ch()

        Else
            MsgBox(problem)
        End If



    End Sub

    Private Sub ch()
        If TextBox2.Text <> "" Then
            If insertedLayers > TextBox2.Text Then
                Panel1.Enabled = False
                'Form6.Show()

                Dim YesOrNoAnswerToMessageBox As String
                Dim QuestionToMessageBox As String

                QuestionToMessageBox = "Do you like to make new??"

                YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "Prompt")

                If YesOrNoAnswerToMessageBox = vbNo Then

                    Me.Hide()
                    ' Form6.Show()
                Else
                    MakeNew()
                End If
            Else
                Panel1.Enabled = True

            End If
        End If
    End Sub


    Private Sub MakeNew()
        Tid = 0
        insertedLayers = 1
        numlayer.Text = ""
        LayerMake.Items.Clear()
        TextBox1.Enabled = True
        TextBox1.Text = ""
        TextBox2.Text = ""
        LayerMake.Visible = False
        Panel1.Visible = False
        Me.Size = New System.Drawing.Size(342, 228)
        Panel1.Enabled = True
    End Sub
End Class